package org.coc.iot.boot;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * Druid 引导配置 <br />
 * Created by asher on 2017/3/6.
 */
@Configuration
public class Druid {
    private static Logger logger = LoggerFactory.getLogger(Druid.class);

    @Bean(initMethod = "init", destroyMethod = "close") // 声明其为 Bean 实例
    @Primary  // 在同样的 DataSource 中，首先使用被标注的 DataSource
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }
}
